package com.itheima_07;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;

public class ListDemo {
    public static void main(String[] args) {
        //创建集合对象ArrayList
        ArrayList<String> array = new ArrayList<String>();

        array.add("hello");
        array.add("world");
        array.add("java");

        //增强For遍历
        for (String s : array){
            System.out.println(s);
        }
        System.out.println("-----------------------");

        //普通For循环
        for (int i =0;i<array.size();i++){
            String s = array.get(i);
            System.out.println(s);
        }
        System.out.println("-----------------------");

        //迭代器
        Iterator<String> itr = array.iterator();
        while (itr.hasNext()) {
            String s = itr.next();
            System.out.println(s);
        }
        System.out.println("-----------------------");

        LinkedList<String> linkedList = new LinkedList<String>();

        linkedList.add("hello");
        linkedList.add("world");
        linkedList.add("java");

        //增强For遍历
        for (String s : linkedList){
            System.out.println(s);
        }
        System.out.println("-----------------------");

        //普通For循环
        for (int i =0;i<linkedList.size();i++){
            String s = linkedList.get(i);
            System.out.println(s);
        }
        System.out.println("-----------------------");

        //迭代器
        Iterator<String> itr2 = linkedList.iterator();
        while (itr2.hasNext()){
            String s = itr2.next();
            System.out.println(s);
        }





    }
}









